package y23.Sep;
//https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
//26. 删除有序数组中的重复项
public class Test4 {
    public static void main(String[] args) {
        Solution2 solution2 = new Solution2();
        int[] nums1 = {1,1,2};
        System.out.println(solution2.removeDuplicates(nums1));
        int[] nums2 = {0,0,1,1,1,2,2,3,3,4};
        System.out.println(solution2.removeDuplicates(nums2));
    }

}
class Solution2 {
    public int removeDuplicates(int[] nums) {
        int p = 0, q = 0;
        while (q < nums.length) {
            if (nums[p] != nums[q]) {
                p++;
                nums[p] = nums[q];
            }
            q++;
        }
        return p + 1;
    }
}
